//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Policy Injection Application Block
//===============================================================================

using System;
using System.Reflection;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.Unity.InterceptionExtension;
using EntLibContrib.PolicyInjection.Configuration;

namespace EntLibContrib.PolicyInjection.MatchingRules
{
	/// <summary>
	/// Not Matching Rule
	/// </summary>
	[ConfigurationElementType(typeof(NotMatchingRuleData))]
	public class NotMatchingRule : IMatchingRule
	{
		#region Fields
		private IMatchingRule negated;
		#endregion

		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="NotMatchingRule"/> class.
		/// </summary>
		/// <param name="negated">The negated.</param>
		public NotMatchingRule(IMatchingRule negated)
		{
			if (negated == null)
				throw new ArgumentNullException("negated");

			this.negated = negated;
		}
		#endregion

		#region IMatchingRule Members
		/// <summary>
		/// Matches the specified member.
		/// </summary>
		/// <param name="member">The member.</param>
		/// <returns>
		/// true if the rule applies, false if it doesn't.
		/// </returns>
		public bool Matches(MethodBase member)
		{
			return !negated.Matches(member);
		}
		#endregion
	}
}
